﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace EasyPath
{
    class SortableBindingList<T> : BindingList<T>
    {
        public void Sort()
        {
            var list = Items as List<T>;
            if (list == null)
            {
                throw new InvalidOperationException("Apparently the binding list cannot be sorted.");
            }

            list.Sort();

            OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, 0));
        }

        public void Reverse()
        {
            var list = Items as List<T>;
            if (list == null)
            {
                throw new InvalidOperationException("Apparently the binding list cannot be reversed.");
            }

            list.Reverse();

            OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, 0));
        }
    }
}
